<?php

use Biz\service\package\PackageOrder;
use Biz\service\trade\UserAddress;
use Doraemon\tools\Log;
use Hhz\AdministrativeRegion\Region;

class OrderInfoAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;
    public function main()
    {
        $orderNo = $this->getRequest()->getPost('order_no');
        if (empty($orderNo)) {
            throw new \Exception('商品id必传');
        }

        // 商品信息
        $order = PackageOrder::getPayOrder($this->uid);
        $data['package_id'] = $order['package_id'];
        $address = UserAddress::getDefaultAddress($this->uid);
        // 发货地址
        if (empty($address)) {
            $data['accept_name'] = '';
            $data['address'] = '';
            $data['mobile'] = '';
            $data['province'] = '';
            $data['city'] = '';
            $data['info_address'] = '';
            $data['address_id'] = '';
            $data['area_code'] = 0;
        } else {
            if (!empty($address['area_code'])) {
                $province = substr($address['area_code'], 0, 2) . '0000';
                $city = Region::getCityCode($address['area_code']);
                $area = $address['area_code'];
            } else {
                $province = $address['province'];
                $city = $address['city'];
                $area = $address['area'];
            }
            $data['accept_name'] = $address['accept_name'];
            $data['address'] = $address['address'];
            $data['mobile'] = $address['mobile'];
            $data['province'] = $province;
            $data['city'] = $city;
            $data['info_address'] = $address['info_address'];
            $data['address_id'] = $address['id'];
            $data['area_code'] = $area;
        }
        Log::info('package-order_info-log', [$data, $address, $this->uid, $orderNo]);
        $this->setSuccess($data, self::API_CODE_SUCCES);
    }
}